package com.lc.luzhengtang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.flyco.tablayout.SlidingTabLayout;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.fragment.SimpleOrderFragment;
import com.zcx.helper.activity.AppV4Activity;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by Administrator on 2017/5/4.
 */


public class OrderAllActivity extends AppV4Activity implements com.lc.luzhengtang.interfaces.NoticeActivity<Integer> {
    public static OrderAllActivity instance = null;

    public static final String POSITION_KEY = "POSITION_KEY";

    @BindView(R.id.img_news)
    ImageView imgNews;
    /*  @BindView(R.id.indicator)
      TabPageIndicator indicator;*/
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private final String[] mTitles = {
            "待付款", "待发货", "待收货",
            "待评价", "退货/退款"

    };
    @BindView(R.id.tl_2)
    SlidingTabLayout tl2;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    MyPagerAdapter mAdapter;

    private final String[] Status = {
            "1", "2", "3", "4", "7"
    };

    String getids;

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Bundle bundle = intent.getExtras();
        if (bundle == null) {
            viewPager.setCurrentItem(1);
            ((SwipeRefreshLayout.OnRefreshListener) mFragments.get(0)).onRefresh();
        } else {
            viewPager.setCurrentItem(bundle.getInt(POSITION_KEY));
        }


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_orderall);
        ButterKnife.bind(this);
        instance = this;
        for (String title : Status) {
            mFragments.add(SimpleOrderFragment.getInstance(title));
        }

        mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mAdapter);
        tl2.setViewPager(viewPager);
        getids = getIntent().getStringExtra("ids");
        if (TextUtils.isEmpty(getids)) {

        } else if (getids.equals("2")) {
            viewPager.setCurrentItem(1);
        } else if (getids.equals("3")) {
            viewPager.setCurrentItem(2);
        } else if (getids.equals("4")) {
            viewPager.setCurrentItem(3);
        } else if (getids.equals("5")) {
            viewPager.setCurrentItem(4);
        }


    }

    @OnClick({R.id.img_news, R.id.viewPager})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_news:
                finish();
                break;
            case R.id.viewPager:
                break;
        }
    }

    @Override
    public void onRefresh(Integer integer) {
        viewPager.setCurrentItem(integer);
        ((SwipeRefreshLayout.OnRefreshListener) mFragments.get(integer)).onRefresh();
    }

    public void getJump() {

    }


    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
//            return dataBeen.size();
            return mTitles.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
//
            return mTitles[position];
//            return dataBeen.get(position).getTitle();

        }

        @Override
        public Fragment getItem(int position) {
            //  return mFragments.get(position);
            return mFragments.get(position);
        }
    }
}
